export default {

	/* 返回对象实例 */
	make(vm) {
		return (this.vm = vm), this;
	},

	showLoading(title) {
		uni.showLoading({
			mask: true,
			title: title || false,
		});
	},

	hideLoading() {
		uni.hideLoading();
	},

	toast(message) {
		return new Promise((resolve, reject) => {
			uni.showToast({
				icon: 'none',
				title: message,
				duration: 2000
			});
			setTimeout(() => {
				uni.hideToast();
				resolve();
			}, 2200);
		});
	},

	success(message) {
		uni.showToast({
			mask: true,
			icon: 'success',
			title: message,
			duration: 2000
		});
		setTimeout(resolve, 2100);
	},

	confirm(message, title) {
		return new Promise((resolve, reject) => {
			uni.showModal({
				title: title || '确认？',
				content: message,
				success(res) {
					if (res.confirm) {
						resolve(true);
					} else if (res.cancel) {
						resolve(false)
					} else {
						reject();
					}
				}
			});
		});
	},

	alert(message, title) {
		return new Promise((resolve, reject) => {
			uni.showModal({
				title: title || '提示',
				content: message,
				showCancel: false,
				success(res) {
					if (res.confirm) {
						resolve();
					} else {
						reject()
					}
				}
			})
		});
	}
}
